package view;

import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

import runner.Simulator;

/**
 * Class to create the total frame for the simulator, adding all the views
 * @author Projectgroep 5
 *
 */
public class TotalView extends JFrame {
	
	private Simulator simulator;
	// The views to add
	private AnimatedView view;
	private CirkelView pieView;
	private BarChart barView;
	private TextView textView;
	private JPanel viewPanel;
	
	/**
	 * Create a new frame to display the simulation in all given views
	 * @param simulator the simulator
	 * @param view the animation view
	 * @param pieView the piechart view
	 * @param barView the barchart view
	 * @param textView the textview
	 */
	public TotalView(Simulator simulator, AnimatedView view, CirkelView pieView, BarChart barView, TextView textView) {
		this.simulator = simulator;
		this.view = view;
		this.pieView = pieView;
		this.barView = barView;
		this.textView = textView;
        
		setTitle("Simulator vossen en konijnen");
		makeFrame();
		pack();
		this.setExtendedState(JFrame.MAXIMIZED_BOTH);

		setVisible(true);
	}
	
	/**
	 * Making the frame for TotalView, adding the buttons and add all views
	 */
	public void makeFrame()
    {
                
        JPanel panel = new JPanel();
        panel.setLayout(new GridLayout(0, 1));
        JButton oneStep = new JButton("Step 1");
        oneStep.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) { 
        		simulator.simulate(1);
        	}
        });
        panel.add(oneStep);
        
        JButton twentySteps = new JButton("Step 20");
        twentySteps.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		simulator.simulate(20);
        	}
        });
        panel.add(twentySteps);
        
        JButton hundredSteps = new JButton("Step 100");
        hundredSteps.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) { 
        		simulator.simulate(100);
        	}
        });
        panel.add(hundredSteps);
        
        JButton start = new JButton("Start");
        start.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) {
        		simulator.start();
        	
        }});
        JButton pauze = new JButton("Pauze");
        pauze.addActionListener(new ActionListener() {
        	public void actionPerformed(ActionEvent e) { 
        		simulator.stop();
        	
        }});
        panel.add(start);
        panel.add(pauze);
        
        viewPanel = new JPanel();
        viewPanel.setLayout(new GridLayout(0,3));
        viewPanel.add(view);
        JPanel otherViews = new JPanel();
        otherViews.setLayout(new GridLayout(2,0));
        otherViews.add(pieView);
        otherViews.add(barView);
        viewPanel.add(otherViews);
        viewPanel.add(textView);
                
        Container contents = getContentPane();
        contents.add(viewPanel, BorderLayout.CENTER);
        contents.add(panel, BorderLayout.WEST);
    }
}
